{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "nearby-mayor",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/encode-and-decode-tinyurl\n",
    "\n",
    "\n",
    "Runtime: 8 ms, faster than 25.07% of C++ online submissions for Encode and Decode TinyURL.\n",
    "Memory Usage: 7.1 MB, less than 61.13% of C++ online submissions for Encode and Decode TinyURL.\n",
    "\n",
    "\n",
    "```cpp\n",
    "#include <vector>\n",
    "#include <algorithm>\n",
    "#include <map>\n",
    "#include <string>\n",
    "\n",
    "\n",
    "using namespace std;\n",
    "\n",
    "class Solution {\n",
    "public:\n",
    "    map<string, string> m {\n",
    "        {\"a\", \"b\"},\n",
    "        {\"b\", \"a\"}\n",
    "    };\n",
    "    Solution() {\n",
    "        //6:22\n",
    "        //6:30\n",
    "    }\n",
    "\n",
    "    // Encodes a URL to a shortened URL.\n",
    "    string encode(string longUrl) {\n",
    "        string s;\n",
    "        for (auto v : longUrl) {\n",
    "            string c(1, v);\n",
    "            if (m.count(c) > 0) {\n",
    "                s += m[c];\n",
    "            } else {\n",
    "                s += c;\n",
    "            }\n",
    "        }\n",
    "        return s;\n",
    "    }\n",
    "\n",
    "    // Decodes a shortened URL to its original URL.\n",
    "    string decode(string shortUrl) {\n",
    "        string s;\n",
    "        for (auto v : shortUrl) {\n",
    "            string c(1, v);\n",
    "            bool ok = false;\n",
    "            for (auto item : m) {\n",
    "                if (item.second == c) {\n",
    "                    s += item.first;\n",
    "                    ok = true;\n",
    "                    break;\n",
    "                }\n",
    "            }\n",
    "            if (ok == false) {\n",
    "                s += c;\n",
    "            }\n",
    "        }\n",
    "        return s;\n",
    "    }\n",
    "};\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "curious-senator",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C++17",
   "language": "C++17",
   "name": "xcpp17"
  },
  "language_info": {
   "codemirror_mode": "text/x-c++src",
   "file_extension": ".cpp",
   "mimetype": "text/x-c++src",
   "name": "c++",
   "version": "17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
